const {
    LinValidator,
    Rule
} = require('../../core/lin-validator-v2')

const {
    optionsIdValidator,
    PositiveIdValidator
} = require('./common')

class editPasswordValidator extends LinValidator { //修改密码
    constructor() {
        super()
        this.id = [
            new Rule('isOptional'),
            new Rule('isInt', '必须是正整数', {
                min: 1,
                max: 32
            })
        ]
        this.password1 = [
            // 用户指定范围 123456 $^
            new Rule('isLength', '密码至少6个字符，最多32个字符', {
                min: 6,
                max: 32
            }),
            new Rule('matches', '密码不符合规范', '^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]')

        ]
        this.password2 = this.password1
    }

    validatePassword(vals) {
        const psw1 = vals.body.password1
        const psw2 = vals.body.password2
        if (psw1 !== psw2) {
            throw new Error('两个密码必须相同')
        }
    }
}

class upRegisterValidator extends optionsIdValidator { //修改用户
    constructor() {
        super()
        this.username = [
            new Rule('isOptional'),
            new Rule('isLength', '用户名不符合长度规范', {
                min: 1,
                max: 32
            }),
        ]
        this.nickname = [
            new Rule('isOptional'),
            new Rule('isLength', '不符合长度规范', {
                min: 1,
                max: 32
            }),
        ]
        this.avatar = [
            new Rule('isOptional'),
            new Rule('isLength', '不符合长度规范', {
                min: 1,
                max: 32
            }),
        ]
        this.type = [
            new Rule('isOptional'),
            new Rule('isInt', '需要传入1-3', {
                min: 1,
                max: 3
            }),
        ]
    }
}
class addRolesValidator extends LinValidator { //添加角色
    constructor() {
        super()
        this.rolesName = [
            new Rule('isLength', '必传',{
                min:1,
                max:32
            }),
        ]
        this.weights = [
            new Rule('isInt', '需要传入整数'),
        ]
        this.rolesType = [
            new Rule('isInt', '需要传入整数'),
        ]
    }
}
class RolesBtnListValidator extends LinValidator { //角色按钮列表
    constructor() {
        super()
        this.menuName = [
            new Rule('isOptional'),
            new Rule('isLength', '必传',{
                min:1,
                max:32
            }),
        ]
        this.rolesType = [
            new Rule('isInt', '需要传入整数'),
        ]
    }
}
class upRolesValidator extends addRolesValidator { //修改角色
    constructor() {
        super()
        this.id = new Rule('isLength','必传',{
            min:1,
            max:32
        })
    }
}

module.exports = {
    editPasswordValidator,
    upRegisterValidator,
    upRolesValidator,
    addRolesValidator,
    RolesBtnListValidator,
}